//
//  PriceRangeTableViewCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/10.
//

import UIKit

protocol PriceRangeTableViewCellDelegate {
    func selectPriceRange()
}

class PriceRangeTableViewCell: UITableViewCell {
    var delegate: PriceRangeTableViewCellDelegate!
    var startPriceBtn: UIButton!
    var gapView: UIView!
    var endPriceBtn: UIButton!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?){
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.clipsToBounds = true
        self.backgroundColor = .white
  
        self.startPriceBtn = UIButton(frame: CGRect.zero)
        self.startPriceBtn.backgroundColor = .white
        self.startPriceBtn.setTitleColor(Theme.titleLabColor, for: .normal)
        self.startPriceBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCRegular, size: 12)
        self.startPriceBtn.layer.cornerRadius = 16
        self.startPriceBtn.clipsToBounds = true
        self.startPriceBtn.layer.borderWidth = 1
        self.startPriceBtn.layer.borderColor = UIColor(hex: 0x939AA8 ,alpha: 0.12).cgColor
        self.startPriceBtn.addTarget(self, action: #selector(priceBtnAntion), for: .touchUpInside)
        self.contentView.addSubview(self.startPriceBtn)
        

        
        self.gapView = UIView(frame: CGRect.zero)
        self.gapView.backgroundColor = UIColor(hex: 0x939AA8)
        self.contentView.addSubview(self.gapView)
        
        self.endPriceBtn = UIButton(frame: CGRect.zero)
        self.endPriceBtn.backgroundColor = .white
        self.endPriceBtn.setTitleColor(Theme.titleLabColor, for: .normal)
        self.endPriceBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCRegular, size: 12)
        self.endPriceBtn.layer.cornerRadius = 16
        self.endPriceBtn.clipsToBounds = true
        self.endPriceBtn.layer.borderWidth = 1
        self.endPriceBtn.layer.borderColor = UIColor(hex: 0x939AA8 ,alpha: 0.12).cgColor
        self.endPriceBtn.addTarget(self, action: #selector(priceBtnAntion), for: .touchUpInside)
        self.contentView.addSubview(self.endPriceBtn)
        
        self.startPriceBtn.setTitle(MMLocalizedString("all", comment: "全部"), for: .normal)
        self.endPriceBtn.setTitle(MMLocalizedString("all", comment: "全部"), for: .normal)
        
        self.addLayout()
        
    }
    
    func addLayout(){
        let width = (kScreenWidth - 60)/2
        self.startPriceBtn.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(14)
            make.width.equalTo(width)
            make.height.equalTo(32)
            make.bottom.equalTo(-30)
        }
        
        self.gapView.snp.makeConstraints { make in
            make.left.equalTo(self.startPriceBtn.snp.right).offset(8)
            make.width.equalTo(16)
            make.height.equalTo(2)
            make.centerY.equalTo(self.startPriceBtn.snp.centerY)
        }
        
        
        self.endPriceBtn.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.right.equalTo(-14)
            make.width.equalTo(width)
            make.height.equalTo(38)
            make.bottom.equalTo(-30)
        }
    }
    
    
    @objc func priceBtnAntion(){
        self.delegate?.selectPriceRange()
    }
  
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
